package jam.UserInterface.UI;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.*;
import java.awt.*;

public class AutoreplaceSmiles extends JTextPane {
    
    String[] sets = {":)",":-)",";)",";-)",":(",":-(",";(",";-(",":d",":D",":o",":-o",":p",":P",
		     "[angry]","[biggrin]","[blink]","[blush]","[bored]","[closedeyes]","[confused]",
		     "[cool]","[crying]","[cursing]","[drool]","[glare]","[huh]","[laugh]","[lol]",
		     "[love]","[loveeyes]","[mad]","[mellow]","[ohmy]","[rolleyes]","[sad]","[scared]",
		     "[sleep]","[smile]","[sneaky]","[thumbdown]","[thumbup]","[thumbup1]","[tongue]",
		     "[tongue2]","[tongue_smilie]","[unsure]","[w00t]","[wink]"};
    JEditorPane messageBox;
    String sname;
    
    public AutoreplaceSmiles(JEditorPane messageBox) {
        this.messageBox = messageBox;
        String msgBox = messageBox.getText();
        
        for (String s: sets){
	    if (msgBox.contains(s)){
		
		sname=s;
		if (sname==":)"||sname==":-)")
		    sname="[smile]";
                else if(sname==":("||sname==":-(")
		    sname="[sad]";
                else if(sname==";("||sname==";-(")
		    sname="[crying]";
                else if(sname==":D"||sname==":d"||sname==":-D")
		    sname="[biggrin]";
                else if(sname==":P"||sname==":p"||sname==":-P")
		    sname="[tongue_smilie]";
                else if(sname==";P"||sname==";p"||sname==";-P")
		    sname="[tongue]";
                else if(sname==";)"||sname==";-)")
		    sname="[wink]";
                else if(sname==":o"||sname==":-o")
		    sname="[ohmy]";
		
		String currentDirectory = System.getProperty("user.dir");	
                String picName= sname.concat(".gif");
                String emoPath= currentDirectory + "/src/jam/UserInterface/Smileys/" + picName;
                messageBox.setText(messageBox.getText().replace(s,"<img src=\"file://" + emoPath + "\">"));       		
	    }
        }
    }   
}